﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeChatV3Pay.Core.Dtos
{
    public class FromItem
    {
        [JsonProperty("account")]
        public string Account { get; set; }

        [JsonProperty("amount")]
        public int Amount { get; set; }
    }

    public class RefundAmount
    {
        /// <summary>
        /// 退款金额
        /// </summary>
        /// <remarks>退款金额，单位为分，只能为整数，不能超过原订单支付金额。</remarks>
        [JsonProperty("refund")]
        public int Refund { get; set; }

        /// <summary>
        /// 退款出资账户及金额
        /// </summary>
        [JsonProperty("from")]
        public List<FromItem> From { get; set; }

        /// <summary>
        /// 原订单金额	
        /// </summary>
        /// <example>1000</example>
        /// <remarks>原支付交易的订单总金额，单位为分，只能为整数。</remarks>
        [JsonProperty("total")]
        public int Total { get; set; }

        /// <summary>
        /// 退款币种	
        /// </summary>
        /// <example>1000</example>
        /// <remarks>符合ISO 4217标准的三位字母代码，目前只支持人民币：CNY。</remarks>
        [JsonProperty("currency")]
        public string Currency { get; set; }
    }

    /// <summary>
    /// 退款商品
    /// </summary>
    public class GoodsDetailItem
    {
        /// <summary>
        /// 商户侧商品编码
        /// </summary>
        /// <remarks>由半角的大小写字母、数字、中划线、下划线中的一种或几种组成</remarks>
        [JsonProperty("merchant_goods_id")]
        public string MerchantGoodsId { get; set; }

        /// <summary>
        /// 微信支付商品编码
        /// </summary>
        [JsonProperty("wechatpay_goods_id")]
        public string WechatpayGoodsId { get; set; }

        /// <summary>
        /// 商品名称
        /// </summary>
        [JsonProperty("goods_name")]
        public string GoodsName { get; set; }

        /// <summary>
        /// 商品单价
        /// </summary>
        [JsonProperty("unit_price")]
        public int UnitPrice { get; set; }

        /// <summary>
        /// 商品退款金额
        /// </summary>
        [JsonProperty("refund_amount")]
        public int RefundAmount { get; set; }

        /// <summary>
        /// 商品退货数量
        /// </summary>
        [JsonProperty("refund_quantity")]
        public int RefundQuantity { get; set; }
    }

    public class RefundsDto
    {
        /// <summary>
        /// 微信支付订单号
        /// </summary>
        /// <example>1217752501201407033233368018</example>
        /// <remarks>原支付交易对应的微信订单号，与out_trade_no二选一</remarks>
        [JsonProperty("transaction_id")]
        public string TransactionId { get; set; }

        /// <summary>
        /// 商户订单号
        /// </summary>
        /// <example>1217752501201407033233368018</example>
        /// <remarks>原支付交易对应的商户订单号，与transaction_id二选一</remarks>
        [JsonProperty("out_trade_no")]
        public string OutTradeNo { get; set; }

        /// <summary>
        /// 商户退款单号
        /// </summary>
        /// <example>1217752501201407033233368018</example>
        /// <remarks>商户系统内部的退款单号，商户系统内部唯一，只能是数字、大小写字母_-|*@ ，同一退款单号多次请求只退一笔。</remarks>
        [JsonProperty("out_refund_no")]
        public string OutRefundNo { get; set; }

        /// <summary>
        /// 退款原因
        /// </summary>
        /// <example>1217752501201407033233368018</example>
        /// <remarks>若商户传入，会在下发给用户的退款消息中体现退款原因</remarks>
        [JsonProperty("reason")]
        public string Reason { get; set; }

        /// <summary>
        /// 退款结果回调url
        /// </summary>
        /// <remarks>异步接收微信支付退款结果通知的回调地址，通知url必须为外网可访问的url，不能携带参数。 如果参数中传了notify_url，则商户平台上配置的回调地址将不会生效，优先回调当前传的这个地址。</remarks>
        [JsonProperty("notify_url")]
        public string NotifyUrl { get; set; }

        /// <summary>
        /// 退款资金来源
        /// </summary>
        /// <example>AVAILABLE</example>
        /// <remarks>若传递此参数则使用对应的资金账户退款，否则默认使用未结算资金退款（仅对老资金流商户适用）</remarks>
        [JsonProperty("funds_account")]
        public string FundsAccount { get; set; }

        /// <summary>
        /// 金额信息
        /// </summary>
        [JsonProperty("amount")]
        public RefundAmount Amount { get; set; }

        /// <summary>
        /// 退款商品
        /// </summary>
        [JsonProperty("goods_detail")]
        public List<GoodsDetailItem> GoodsDetail { get; set; }
    }

}
